<%--
  Created by IntelliJ IDEA.
  User: Hexun
  Date: 2017/7/27 0027
  Time: 16:12
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>体校考试系统</title>
    <meta name="description" content="这是一个 index 页面">
    <meta name="keywords" content="index">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="icon" type="image/png" href="/assets/i/favicon.png">
    <link rel="apple-touch-icon-precomposed" href="/assets/i/app-icon72x72@2x.png">
    <meta name="apple-mobile-web-app-title" content="Amaze UI"/>
    <link rel="stylesheet" href="/assets/css/amazeui.min.css"/>
    <link rel="stylesheet" href="/assets/css/admin.css">
    <link rel="stylesheet" href="/assets/css/app.css">
    <script src="/assets/js/jquery.min.js"></script>
    <script>

    </script>
</head>
<body>
<%@ include file="/NavMenu.jsp" %>
<div style="float: left;margin-left: 2%;width: 76%">
    <div class="tpl-portlet-components">
        <div class="portlet-title">
            <div class="caption font-green bold" style="width: 100%;">
                <span class="am-icon-code"></span> 试卷分配
                <span style="float: right"><button class="am-btn am-btn-danger" onclick=" $('#my-confirm').modal('open');">清除现有考试信息</button></span>
            </div>
        </div>
        <div class="tpl-block">
            <div style="width: 100%;">
                <div style="width: 68%;float: left">
                    <table width="100%" class="am-table am-table-bordered am-table-hover">
                        <tr align="center" bgcolor="#87cefa">
                            <td colspan="4">已生成的母卷</td>
                        </tr>
                        <tr align="center">
                            <td width="30%">科目</td>
                            <td>母卷编号</td>
                            <td>时间</td>
                            <td>操作</td>
                        </tr>
                        <c:forEach var="mujuan" items="${MujuanList}">
                            <tr align="center" id="tr${mujuan.id}">
                                <td width="30%">${mujuan.name}</td>
                                <td>${mujuan.exam_no}</td>
                                <td hidden><input type="hidden" value="${mujuan.cid}" id="tr${mujuan.id}_courseId"></td>
                                <c:choose>
                                    <c:when test="${mujuan.exam_time eq 0 or empty mujuan.exam_time}">
                                        <td><input type="text" name="" id="tr${mujuan.id}_time" value=""></td>
                                        <td>
                                            <button class="am-btn am-btn-primary" onclick="updateTimu(${mujuan.id})">
                                                添加至当前考试
                                            </button>
                                        </td>
                                    </c:when>
                                    <c:otherwise>
                                        <td><input type="text" name="" id="tr${mujuan.id}_time"
                                                   value="${mujuan.exam_time}"
                                                   style="background: #FFF8DC;"></td>
                                        <td>
                                            <button class="am-btn am-btn-success" onclick="updateTimu(${mujuan.id})">修改当前考试时间</button>
                                        </td>
                                    </c:otherwise>
                                </c:choose>
                            </tr>
                        </c:forEach>
                    </table>
                </div>
                <div style="width: 30%;float: right">
                    <table width="100%" class="am-table am-table-bordered am-table-hover">
                        <tr align="center" bgcolor="#87cefa">
                            <td class="head" colspan="3">当前的考试</td>
                        </tr>
                        <tr align="center">
                            <td>科目</td>
                            <td>场次</td>
                            <td>时间(分钟)</td>
                        </tr>

                        <c:forEach items="${examList}" var="exam">
                            <tr align="center">
                                <td>${exam.name}</td>
                                <td>${exam.exam_no}</td>
                                <td>${exam.exam_time}</td>
                            </tr>
                        </c:forEach>
                    </table>
                </div>
            </div>
        </div>
        <!--结果模态窗口-->
        <div class="am-modal am-modal-alert" tabindex="-1" id="my-alert">
            <div class="am-modal-dialog">
                <div class="am-modal-bd" id="message">
                </div>
                <div class="am-modal-footer">
                    <span class="am-modal-btn" id="alert_cfm">确定</span>
                </div>
            </div>
        </div>
        <!--确认删除所有考试信息模态窗口-->
        <div class="am-modal am-modal-confirm" tabindex="-1" id="my-confirm">
            <div class="am-modal-dialog">
                <div class="am-modal-bd">
                    确定删除现有考试信息吗？
                </div>
                <div class="am-modal-footer">
                    <span class="am-modal-btn" data-am-modal-cancel>取消</span>
                    <span class="am-modal-btn" data-am-modal-confirm id="delete_cfm">确定</span>
                </div>
            </div>
        </div>
    </div>

</div>
<script>
    function updateTimu(id) {
        var tr = document.getElementById("tr" + id);
        var time = document.getElementById("tr" + id + "_time").value;
        var courseId = document.getElementById("tr" + id + "_courseId").value;
        var exam_no = tr.cells[1].innerText;
        $.post("/exam/updateTime", {time: time, exam_no: exam_no, courseId: courseId}, function (res) {
            $('#message').text(res);
            $('#my-alert').modal('open');
        });
    }
    $('#my-alert').on('click', function () {
        window.location.href="/exam/show";
    });
    $('#delete_cfm').on('click',function(){
        $.get("/exam/deleteAllExam",function(res){
            $('#message').text(res);
            $('#my-alert').modal('open');
        });
    })
</script>
</body>
</html>
